package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.pojo.Building;
import cn.bgs.pojo.Cell;
import cn.bgs.pojo.CellIntermediate;
import cn.bgs.service.IBuildingService;
import cn.bgs.service.ICellService;
import cn.bgs.vo.UserVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 单元表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/cell")
public class CellController {


    @Autowired
    private ICellService iCellService;

    @GetMapping({"findCellPc"})
    public PageInfo<CellIntermediate> findCellPc(String communityId,String identity,Integer middleState,Integer pagesize, Integer pagenow){
        PageInfo<CellIntermediate> cells = this.iCellService.findCellPc(communityId,identity,middleState,pagesize,pagenow);
        return cells;
    }

    @GetMapping({"delPc"})
    public R delPc(Integer id){
        this.iCellService.delPc(id);
        return R.ok();
    }

    @PostMapping({"loadPc"})
    public R loadPc(Integer id){
        List<CellIntermediate> cellIntermediate = this.iCellService.loadPc(id);
        return R.ok().data("data", cellIntermediate);
    }

    @PostMapping({"addUserPc"})
    public R addUserPc(@RequestBody UserVo forms){
        this.iCellService.addUserPc(forms);
        return R.ok();
    }

    @PostMapping({"updatePc"})
    public R updatePc(@RequestBody CellIntermediate forms){
        this.iCellService.updatePc(forms);
        return R.ok();
    }

    @GetMapping("/appFindCell/{buildingId}")
    @ApiOperation(value = "app我的房屋(添加房屋的单元查询)")
    public R appFindCell(@PathVariable Integer buildingId){

        List<Cell> cell = iCellService.appFindCell(buildingId);
        if (cell != null){
            return R.ok().data("cell",cell);
        }else {
            return R.error();
        }
    }

}
